import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/views/Layout/index.vue'
import Login from '@/views/Login/index.vue'
import Home from '@/views/Home/index.vue'
import ProductList from '@/views/ProductList/index.vue'
import ProductDetail from '@/views/ProductDetail/index.vue'
import Cart from '@/views/Cart/index.vue'
import Pay from '@/views/Pay/index.vue'
import Register from '@/views/Register/index.vue'
import NewsList from '@/views/NewsList/index.vue'
import SubmintOrder from '@/views/SubmitOrder/inidex.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component:Layout,
      children: [
        {
          path: '',
          component: Home
        },
        {
          path: 'productlist',
          component: ProductList
        },
        {
          path: 'newslist',
          component: NewsList
        },
        {
          path: 'cart',
          component: Cart
        },
        {
          path: 'product',
          component: ProductDetail
        },
        {
          path: 'suborder',
          component: SubmintOrder
        },
        {
          path: 'pay',
          component: Pay
        }
      ]
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/register',
      component: Register
    },
  ],
  // 路由滚动行为配置,切换路由页面，自动滚动到顶部
  scrollBehavior () {
    return {
      top: 0,
    }
  }
})

export default router
